/**
 * 表格中的图片的长度/宽度
 * @type {number}
 */
let size = 45;
/**
 * 表格高度
 * @type {number}
 */
let table_height = 720;
/**
 * 有搜索栏的表格高度
 * @type {number}
 */
let table_height_with_search = 678;
/**
 * 表格分页插件的页码
 * @type {number[]}
 */
let pageList = [10, 20, 50, 100];

/**
 * 删除小图标
 * @type {string}
 */
let icon_delete = "/css/themes/icons/delete.png";

/**
 * 文件上传按钮
 * @type {{handler: handler, text: string, iconCls: string}}
 */
let buttonUpload = buttonUploadHandler(function () {
    imageHandler();
});

function buttonUploadHandler(func) {
    return {
        iconCls: "icon-upload",
        text: "上传图片",
        handler: function() {
            func();
        }
    };
}

/**
 * 渲染文件上传对话框
 * @param requestUrl
 * @param func
 */
function fetchUploadDialog(requestUrl, func) {
    $("#upload_dialog").dialog({
        title: "修改图片",
        modal: true,
        closed: true,
        closable: false,
        draggable: false,
        buttons: [{
            iconCls: "icon-save",
            text: "保存",
            handler: function() {
                let selector = "#upload_form";

                checkForm(selector, function () {
                    let data = $(selector).serialize();

                    ajaxPost(requestUrl, data, function(response) {
                        showMsg(response.message);
                        resetValue("#upload");

                        $(selector).form("clear");
                        $("#upload_dialog").dialog("close");
                        func();
                    }, error);
                });
            }
        }, {
            iconCls: "icon-cancel",
            text: "取消",
            handler: function() {
                resetValue("#upload");

                $("#upload_form").form("clear");
                $("#upload_dialog").dialog("close");
            }
        }]
    });
}

/**
 * 验证是否数字
 * @param number
 * @returns {boolean}
 */
function isNumber(number) {
    let regx = /^[0-9]*$/;

    return regx.test(number);
}

/**
 * 验证手机号格式
 * @param phone
 * @returns {boolean}
 */
function isPhone(phone) {
    // 最新的手机号正则表达式
    let phone_number_reg = /^1[3-9]\d{9}$/;

    return phone_number_reg.test(phone);
}

/**
 * 验证邮箱格式
 * @param email
 * @returns {boolean}
 */
function isEmail(email) {
    // 邮箱正则表达式
    let email_reg = /^(([^()[\]\\.,;:\s@"]+(\.[^()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

    return email_reg.test(email);
}